/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utility;

import weka.core.Instances;
import weka.core.converters.ConverterUtils.DataSource;

public class FileReader {
  
  public static Instances readFile (String filename) {
    try {
      DataSource source = new DataSource(filename);
      Instances data = source.getDataSet();
      return data;
    } catch (Exception e) {
      return null;
    }
  }

  public static void main(String[] args) {
    try {
      DataSource source = new DataSource("specthearttrain.arff");
      Instances data = source.getDataSet();
      // setting class attribute if the data format does not provide this information
      // For example, the XRFF format saves the class attribute information as well
      if (data.classIndex() == -1) {
        data.setClassIndex(data.numAttributes() - 1);
      }
      for (int x = 0 ; x < data.numInstances(); x++) {
        for (int y = 0; y < data.instance(x).numValues(); y++) {
          System.out.print(data.instance(x).stringValue(y) + " ");
        }
        System.out.println();
      }
    } catch (Exception e) {
    }
  }
}
